<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:pe="http://primefaces.org/ui/extensions">

    <h:body>

        <ui:composition template="/resources/template/template.xhtml">

            <ui:define name="content">
                <h:form >
                    <p:panel >
                        <f:facet name="header" >
                            <h:outputLabel value="BHT Income by Categories" ></h:outputLabel>
                        </f:facet>
                        <h:panelGrid columns="2" >
                            <h:outputLabel value="From  " ></h:outputLabel>
                            <p:calendar value="#{inwardReportController1.fromDate}" pattern="dd MMMM yyyy hh:mm:ss a" ></p:calendar>
                            <h:outputLabel value="To  " ></h:outputLabel>
                            <p:calendar value="#{inwardReportController1.toDate}" pattern="dd MMMM yyyy hh:mm:ss a" ></p:calendar>
                            <h:outputLabel value="Admission Type  " ></h:outputLabel>
                            <p:selectOneMenu  id="lstAdmissionType"   value="#{inwardReportController1.admissionType}" >
                                <f:selectItem itemLabel="All Admission Types"/>
                                <f:selectItems  value="#{admissionTypeController.items}" var="myItem" itemValue="#{myItem}" itemLabel="#{myItem.name}"></f:selectItems>
                            </p:selectOneMenu>
                            <h:outputLabel value="BHT Type  " ></h:outputLabel>
                            <p:selectOneMenu   id="cmbBhtType" value="#{inwardReportController1.paymentMethod}"  >
                                <f:selectItem itemLabel="All BHT Types" />                           
                                <f:selectItems value="#{enumController.paymentMethodForAdmission}" />
                            </p:selectOneMenu>
                            <h:outputLabel value="Credit Company  " ></h:outputLabel>
                            <p:selectOneMenu  id="lstCc"   value="#{inwardReportController1.institution}" >
                                <f:selectItem itemLabel="All Credit Companies"/>
                                <f:selectItems  value="#{creditCompanyController.creditCompanies}" var="cc" 
                                                itemValue="#{cc}" itemLabel="#{cc.name}"></f:selectItems>
                            </p:selectOneMenu>



                        </h:panelGrid>
                        <h:panelGrid columns="4">
                            <p:commandButton ajax="false" value="Process" action="#{inwardReportController1.process()}" onclick="onSubmitButton();"  ></p:commandButton>

                            <p:commandButton ajax="false" value="Process Doctor Payment" action="#{inwardReportController1.createDoctorPaymentInward()}" onclick="onSubmitButton();"  ></p:commandButton>

                            <p:commandButton ajax="false" value="Excel" styleClass="noPrintButton" onclick="onSubmitButton();" >
                                <pe:exporter type="xlsx" target="tb1,tb2,tb3,tb4,tb5,tb6,tbl7,tbl8" fileName="bht_income_by_categories"  />
                            </p:commandButton>
                            <p:commandButton value="Print" ajax="false" action="#" >
                                <p:printer target="gpBillPreview"></p:printer>
                            </p:commandButton>

                        </h:panelGrid>
                        <p:panel id="gpBillPreview" styleClass="noBorder summeryBorder">

                            <p:dataTable id="tb1" value="#{inwardReportController1.opdServices}" var="rec" >
                                <f:facet name="header">
                                    <p:outputLabel value="#{sessionController.loggedUser.institution.name}" /><br></br>
                                    <h:outputLabel value="Income by Categories Report"/><br></br>
                                    <h:outputLabel value="From - "/>
                                    <p:outputLabel value="#{inwardReportController1.fromDate}">
                                        <f:convertDateTime pattern="dd/MMM/yyyy - hh:mm:ss a"/>
                                    </p:outputLabel>
                                    <h:outputLabel value=" - To - "/>
                                    <h:outputLabel value="#{inwardReportController1.toDate}">
                                        <f:convertDateTime pattern="dd/MMM/yyyy - hh:mm:ss a"/>
                                    </h:outputLabel><br></br>
                                    <h:panelGrid rendered="#{inwardReportController1.admissionType ne null}">
                                        <h:outputLabel value="#{inwardReportController1.admissionType.name}"/>
                                    </h:panelGrid>
                                    <h:panelGrid rendered="#{inwardReportController1.paymentMethod ne null}">
                                        <h:outputLabel value="#{inwardReportController1.paymentMethod}"/>
                                    </h:panelGrid>
                                    <h:panelGrid rendered="#{inwardReportController1.institution.name ne null}">
                                        <h:outputLabel value="#{inwardReportController1.institution.name}"/>
                                    </h:panelGrid>
                                    <h:outputLabel value="Inward Service"/>
                                </f:facet>
                                <p:column headerText="Category" >
                                    <f:facet name="header" >
                                        <p:outputLabel value="Category" />
                                    </f:facet>
                                    <h:commandLink value="#{rec.category.name}"
                                                   action="#{inwardReportController1.processCategoryBillItems}" >
                                        <f:setPropertyActionListener value="#{rec.category}" target="#{inwardReportController1.category}" />
                                    </h:commandLink>
                                </p:column>
                                <p:column headerText="Count" >
                                    <f:facet name="header" >
                                        <p:outputLabel value="Count" />
                                    </f:facet>
                                    <h:commandLink value="#{rec.count}" action="#{inwardReportController1.processCategoryBillItems}" >
                                        <f:setPropertyActionListener value="#{rec.category}" target="#{inwardReportController1.category}" />
                                    </h:commandLink>
                                </p:column>
                                <p:column headerText="Gross"  style="text-align: right; padding: 5px;" >   
                                    <f:facet name="header" >
                                        <p:outputLabel value="Gross" />
                                    </f:facet>
                                    <h:outputLabel value="#{rec.grossValue}" >
                                        <f:convertNumber pattern="#,##0.00" ></f:convertNumber>
                                    </h:outputLabel>
                                    <f:facet name="footer">
                                        <h:outputLabel value="#{inwardReportController1.opdSrviceGross}">
                                            <f:convertNumber pattern="#,##0.00" />
                                        </h:outputLabel>
                                    </f:facet>
                                </p:column>
                                <p:column headerText="Margin"  style="text-align: right; padding: 5px;"  >   
                                    <f:facet name="header" >
                                        <p:outputLabel value="Margin" />
                                    </f:facet>
                                    <h:outputLabel value="#{rec.margin}" >
                                        <f:convertNumber pattern="#,##0.00" />
                                    </h:outputLabel>
                                    <f:facet name="footer">
                                        <h:outputLabel value="#{inwardReportController1.opdServiceMargin}">
                                            <f:convertNumber pattern="#,##0.00" />
                                        </h:outputLabel>
                                    </f:facet>
                                </p:column>

                                <p:column headerText="Discount"  style="text-align: right; padding: 5px;"  >    
                                    <f:facet name="header" >
                                        <p:outputLabel value="Discount" />
                                    </f:facet>
                                    <h:outputLabel value="#{rec.discount}" >
                                        <f:convertNumber pattern="#,##0.00" ></f:convertNumber>
                                    </h:outputLabel>
                                    <f:facet name="footer">
                                        <h:outputLabel value="#{inwardReportController1.opdServiceDiscount}">
                                            <f:convertNumber pattern="#,##0.00" />
                                        </h:outputLabel>
                                    </f:facet>
                                </p:column>

                                <p:column headerText="Net Amount" style="text-align: right; padding: 5px;" >     
                                    <f:facet name="header" >
                                        <p:outputLabel value="Net Amount" />
                                    </f:facet>
                                    <h:outputLabel value="#{rec.netValue}" >
                                        <f:convertNumber pattern="#,##0.00" />
                                    </h:outputLabel>
                                    <f:facet name="footer">
                                        <h:outputLabel value="#{inwardReportController1.opdServiceNetValue}">
                                            <f:convertNumber pattern="#,##0.00" />
                                        </h:outputLabel>
                                    </f:facet>
                                </p:column> 

                            </p:dataTable>

                            <p:dataTable id="tb2" value="#{inwardReportController1.roomChargeInwards}" var="rm">
                                <f:facet name="header">
                                    <h:outputLabel value="Room Charges"/>
                                    <p:commandButton ajax="false" value="View Detail"
                                                     style="float: right;"
                                                     action="report_income_room" 
                                                     actionListener="#{inwardReportController1.processPatientRooms()}"/>
                                </f:facet>
                                <p:column headerText="Charge Name">
                                    <f:facet name="header" >
                                        <p:outputLabel value="Charge Name" />
                                    </f:facet>
                                    <h:outputLabel value="#{rm.inwardChargeType}"/>
                                </p:column>
                                <p:column headerText="Calculated" style="text-align: right; padding: 5px;">
                                    <f:facet name="header" >
                                        <p:outputLabel value="Calculated" />
                                    </f:facet>
                                    <h:outputLabel value="#{rm.calculated}"/>
                                    <f:facet name="footer">
                                        <h:outputLabel value="#{inwardReportController1.roomGross}">
                                            <f:convertNumber pattern="#,##0.00" />
                                        </h:outputLabel>
                                    </f:facet>
                                </p:column>        
                                <p:column headerText="Margin" style="text-align: right; padding: 5px;">
                                    <f:facet name="header" >
                                        <p:outputLabel value="Margin" />
                                    </f:facet>
                                </p:column>
                                <p:column headerText="Discount" style="text-align: right; padding: 5px;">
                                    <f:facet name="header" >
                                        <p:outputLabel value="Discount" />
                                    </f:facet>
                                    <h:outputLabel value="#{rm.discount}">
                                        <f:convertNumber pattern="#,##0.00" />
                                    </h:outputLabel>
                                    <f:facet name="footer">
                                        <h:outputLabel value="#{inwardReportController1.roomDiscount}">
                                            <f:convertNumber pattern="#,##0.00" />
                                        </h:outputLabel>
                                    </f:facet>
                                </p:column>
                                <p:column headerText="Net Value" style="text-align: right; padding: 5px;">
                                    <f:facet name="header" >
                                        <p:outputLabel value="Net Value" />
                                    </f:facet>
                                    <h:outputLabel value="#{rm.calculated-rm.discount}">
                                        <f:convertNumber pattern="#,##0.00" />
                                    </h:outputLabel>
                                    <f:facet name="footer">
                                        <h:outputLabel value="#{inwardReportController1.roomGross-inwardReportController1.roomDiscount}">
                                            <f:convertNumber pattern="#,##0.00" />
                                        </h:outputLabel>
                                    </f:facet>
                                </p:column>
                            </p:dataTable>

                            <p:dataTable id="tb3" value="#{inwardReportController1.timedServices}" var="tim">
                                <f:facet name="header">
                                    <h:outputLabel value="Timed Service"/>
                                </f:facet>
                                <p:column headerText="Item Name">
                                    <f:facet name="header" >
                                        <p:outputLabel value="Item Name" />
                                    </f:facet>
                                    <h:outputLabel value="#{tim.string}" />
                                </p:column>
                                <p:column headerText="Gross Value" style="text-align: right; padding: 5px;">
                                    <f:facet name="header" >
                                        <p:outputLabel value="Gross Value" />
                                    </f:facet>
                                    <h:outputLabel  value="#{tim.value1}">
                                        <f:convertNumber pattern="#,##0.00" />
                                    </h:outputLabel>
                                    <f:facet name="footer">
                                        <h:outputLabel value="#{inwardReportController1.timedGross}">
                                            <f:convertNumber pattern="#,##0.00" />
                                        </h:outputLabel>
                                    </f:facet>
                                </p:column>
                                <p:column headerText="Margin" style="text-align: right; padding: 5px;">
                                    <f:facet name="header" >
                                        <p:outputLabel value="Margin" />
                                    </f:facet>
                                </p:column>
                                <p:column headerText="Discount" style="text-align: right; padding: 5px;">
                                    <f:facet name="header" >
                                        <p:outputLabel value="Discount" />
                                    </f:facet>
                                    <h:outputLabel value="#{tim.value2}">
                                        <f:convertNumber pattern="#,##0.00" />
                                    </h:outputLabel>
                                    <f:facet name="footer">
                                        <h:outputLabel value="#{inwardReportController1.timedDiscount}">
                                            <f:convertNumber pattern="#,##0.00" />
                                        </h:outputLabel>
                                    </f:facet>
                                </p:column>
                                <p:column headerText="Net Value" style="text-align: right; padding: 5px;">
                                    <f:facet name="header" >
                                        <p:outputLabel value="Net Value" />
                                    </f:facet>
                                    <h:outputLabel  value="#{tim.value1-tim.value2}">
                                        <f:convertNumber pattern="#,##0.00" />
                                    </h:outputLabel>
                                    <f:facet name="footer">
                                        <h:outputLabel value="#{inwardReportController1.timedGross-inwardReportController1.timedDiscount}">
                                            <f:convertNumber pattern="#,##0.00" />
                                        </h:outputLabel>
                                    </f:facet>
                                </p:column>

                            </p:dataTable>

                            <p:dataTable id="tb4" value="#{inwardReportController1.professionals}" var="pro" >
                                <f:facet name="header">
                                    <h:outputLabel value="Professional Fee"/>
                                </f:facet>
                                <p:column headerText="Speciality">
                                    <f:facet name="header" >
                                        <p:outputLabel value="Speciality" />
                                    </f:facet>                                
                                    <h:commandLink value="#{pro.speciality.name}"
                                                   action="#{inwardReportController1.processProfessionalFees}" >
                                        <f:setPropertyActionListener value="#{pro.speciality}" 
                                                                     target="#{inwardReportController1.speciality}" />
                                    </h:commandLink>
                                </p:column>
                                <p:column headerText="Gross" style="text-align: right; padding: 5px;">
                                    <f:facet name="header" >
                                        <p:outputLabel value="Gross" />
                                    </f:facet>
                                    <h:outputLabel value="#{pro.value1}" >
                                        <f:convertNumber pattern="#,##0.00" />
                                    </h:outputLabel>
                                    <f:facet name="footer">
                                        <h:outputLabel value="#{inwardReportController1.professionalGross}">
                                            <f:convertNumber pattern="#,##0.00" />
                                        </h:outputLabel>
                                    </f:facet>
                                </p:column>
                                <p:column headerText="Margin" style="text-align: right; padding: 5px;">
                                    <f:facet name="header" >
                                        <p:outputLabel value="Margin" />
                                    </f:facet>
                                </p:column>
                                <p:column headerText="Discount" style="text-align: right; padding: 5px;">
                                    <f:facet name="header" >
                                        <p:outputLabel value="Discount" />
                                    </f:facet>
                                </p:column>
                                <p:column headerText="Net Value" style="text-align: right; padding: 5px;">
                                    <f:facet name="header" >
                                        <p:outputLabel value="Net Value" />
                                    </f:facet>
                                    <h:outputLabel value="#{pro.value1}" >
                                        <f:convertNumber pattern="#,##0.00" />
                                    </h:outputLabel>
                                    <f:facet name="footer">
                                        <h:outputLabel value="#{inwardReportController1.professionalGross}">
                                            <f:convertNumber pattern="#,##0.00" />
                                        </h:outputLabel>
                                    </f:facet>
                                </p:column>
                            </p:dataTable>

                            <p:dataTable id="tb5" value="#{inwardReportController1.inwardCharges}" var="in">
                                <f:facet name="header">
                                    <h:outputLabel value="Inward Charges"/>
                                    <p:commandButton ajax="false" value="View Detail"
                                                     style="float: right;"
                                                     action="inward_charge" 
                                                     actionListener="#{inwardReportController1.processInwardCharges()}"/>
                                </f:facet>
                                <p:column headerText="Charge Name">
                                    <f:facet name="header" >
                                        <p:outputLabel value="Charge Name" />
                                    </f:facet>
                                    <h:outputLabel value="#{in.string}" />
                                </p:column>
                                <p:column headerText="Gross Value" style="text-align: right; padding: 5px;">
                                    <f:facet name="header" >
                                        <p:outputLabel value="Gross Value" />
                                    </f:facet>
                                    <h:outputLabel value="#{in.value1}">
                                        <f:convertNumber pattern="#,##0.00" />
                                    </h:outputLabel>
                                    <f:facet name="footer">
                                        <h:outputLabel value="#{inwardReportController1.inwardGross}">
                                            <f:convertNumber pattern="#,##0.00" />
                                        </h:outputLabel>
                                    </f:facet>
                                </p:column>
                                <p:column headerText="Margin" style="text-align: right; padding: 5px;">
                                    <f:facet name="header" >
                                        <p:outputLabel value="Margin" />
                                    </f:facet>
                                    <h:outputLabel value="#{in.value2}">
                                        <f:convertNumber pattern="#,##0.00" />
                                    </h:outputLabel>
                                    <f:facet name="footer">
                                        <h:outputLabel value="#{inwardReportController1.inwardMargin}">
                                            <f:convertNumber pattern="#,##0.00" />
                                        </h:outputLabel>
                                    </f:facet>
                                </p:column>
                                <p:column headerText="Discount" style="text-align: right; padding: 5px;">
                                    <f:facet name="header" >
                                        <p:outputLabel value="Discount" />
                                    </f:facet>
                                    <h:outputLabel  value="#{in.value3}">
                                        <f:convertNumber pattern="#,##0.00" />
                                    </h:outputLabel>
                                    <f:facet name="footer">
                                        <h:outputLabel value="#{inwardReportController1.inwardDiscount}">
                                            <f:convertNumber pattern="#,##0.00" />
                                        </h:outputLabel>
                                    </f:facet>

                                </p:column>
                                <p:column headerText="Net Value" style="text-align: right; padding: 5px;">
                                    <f:facet name="header" >
                                        <p:outputLabel value="Net Value" />
                                    </f:facet>
                                    <h:outputLabel  value="#{in.value4}">
                                        <f:convertNumber pattern="#,##0.00" />
                                    </h:outputLabel>
                                    <f:facet name="footer">
                                        <h:outputLabel value="#{inwardReportController1.inwardNetValue}">
                                            <f:convertNumber pattern="#,##0.00" />
                                        </h:outputLabel>
                                    </f:facet>

                                </p:column>
                            </p:dataTable>

                            <p:dataTable value="#{inwardReportController1.paidbyPatient}" id="tbl7" var="pa" rendered="false">
                                <f:facet name="header">
                                    <h:outputLabel value="Paid by Patient"/>
                                </f:facet>
                                <p:column headerText="Bill No">
                                    <f:facet name="header">
                                        <h:outputLabel value="Bill No"/> 
                                    </f:facet>
                                    <h:outputLabel value="#{pa.insId}"></h:outputLabel>
                                </p:column>
                                <p:column headerText="Created Date">
                                    <f:facet name="header">
                                        <h:outputLabel value="Created Date"/> 
                                    </f:facet>
                                    <h:outputLabel value="#{pa.createdAt}"></h:outputLabel>
                                </p:column>
                                <p:column headerText="Net Total" style="text-align: right;">
                                    <f:facet name="header">
                                        <h:outputLabel value="Net Total"/> 
                                    </f:facet>
                                    <h:outputLabel value="#{pa.netTotal}"></h:outputLabel>
                                    <f:facet name="footer">
                                        <h:outputLabel value="#{inwardReportController1.paidbyPatientTotalValue}"></h:outputLabel>
                                    </f:facet>
                                </p:column>                                                               
                            </p:dataTable>

                            <p:dataTable value="#{inwardReportController1.billItems}" id="tbl8" var="bi" rendered="false">
                                <f:facet name="header">
                                    <h:outputLabel value="Credit Company Payment"/>
                                </f:facet>
                                <p:column headerText="Bill No">
                                    <f:facet name="header">
                                        <h:outputLabel value="Bill No"/> 
                                    </f:facet>
                                    <h:outputLabel value="#{bi.bill.insId}"></h:outputLabel>
                                </p:column>
                                <p:column headerText="Created Date">
                                    <f:facet name="header">
                                        <h:outputLabel value="Created Date"/> 
                                    </f:facet>
                                    <h:outputLabel value="#{bi.createdAt}"></h:outputLabel>
                                </p:column>
                                <p:column headerText="Net Total" style="text-align: right;">
                                    <f:facet name="header">
                                        <h:outputLabel value="Net Total"/> 
                                    </f:facet>
                                    <h:outputLabel value="#{bi.netValue}"></h:outputLabel>
                                    <f:facet name="footer">
                                        <h:outputLabel value="#{inwardReportController1.creditPaymentTotalValue}"></h:outputLabel>
                                    </f:facet>
                                </p:column>

                            </p:dataTable>

                            <p:panel  header="Summary" style="text-align: center;">

                                <p:dataTable id="tb6" value="#{inwardReportController1.finalValues}" var="s">
                                    <p:column>
                                        <h:outputLabel value="#{s.string}"/>
                                    </p:column>
                                    <p:column style="text-align: right;">
                                        <h:outputLabel value="#{s.value1}"> 
                                            <f:convertNumber pattern="#,##0.00"/>
                                        </h:outputLabel>

                                    </p:column>
                                </p:dataTable>

                            </p:panel>
                        </p:panel>


                    </p:panel>

                </h:form>
            </ui:define>

        </ui:composition>

    </h:body>
</html>
